<template>
  <div class="edit">
    <h1
      style="
        font-weight: 700;
        font-style: normal;
        font-size: 24px;
        color: #344563;
        margin-bottom: 30px;
      "
    >
      维修质量添加
    </h1>
    <div class="edit-box">
      <div class="form">
        <el-form
          :label-position="labelPosition"
          label-width="80px"
          :model="formLabelAlign"
        >
          <el-form-item label="维修单号">
            <el-input
              v-model="formLabelAlign.id"
              placeholder="系统自动生成"
              disabled
            ></el-input>
          </el-form-item>
          <el-form-item label="装备名称">
            <el-select
              v-model="formLabelAlign.equipmentId"
              placeholder="装备名称"
              clearable
              style="width: 100%"
            >
              <el-option
                :key="v.id"
                v-for="v in dropDown"
                :label="v.equipName"
                :value="v.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="装备编号">
            <el-input
              v-model="formLabelAlign.equipmentNumber"
              placeholder="装备编号"
            ></el-input>
          </el-form-item>
          <el-form-item label="检测结果">
            <el-select
              v-model="formLabelAlign.testResults"
              placeholder="检测结果"
              style="width: 100%"
            >
              <el-option label="已解决" value="1"></el-option>
              <el-option label="已检测" value="2"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <div class="form">
        <el-form
          :label-position="labelPosition"
          label-width="80px"
          :model="formLabelAlign"
        >
          <el-form-item label="开始时间">
            <el-col :span="11" style="width: 100%">
              <el-date-picker
                type="date"
                placeholder="选择日期"
                v-model="formLabelAlign.startTime"
                style="width: 100%"
                value-format="yyyy-mm-dd"
              ></el-date-picker>
            </el-col>
          </el-form-item>
          <el-form-item label="结束时间">
            <el-col :span="11" style="width: 100%">
              <el-date-picker
                type="date"
                placeholder="选择日期"
                v-model="formLabelAlign.endTime"
                style="width: 100%"
                value-format="yyyy-mm-dd"
              ></el-date-picker>
            </el-col>
          </el-form-item>
          <el-form-item label="检测状态">
            <el-select
              v-model="formLabelAlign.testStatus"
              placeholder="检测状态"
              style="width: 100%"
            >
              <el-option label="检测中" value="1"></el-option>
              <el-option label="待检测" value="2"></el-option>
              <el-option label="检查完成" value="3"></el-option>
            </el-select>
          </el-form-item>
          <el-button
            style="margin-right: 20px; width: 100px; margin-left: 150px"
            @click="cancel"
            >取消</el-button
          >
          <el-button
            type="danger"
            style="background: #6554c0; border: none; width: 100px"
            @click="Save"
            >保存</el-button
          >
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      labelPosition: "left",
      formLabelAlign: {
        endTime: "",
        equipmentId: "",
        equipmentNumber: "",
        startTime: "",
        testResults: "",
        testStatus: "",
      },
      dropDown: [],
    };
  },
  methods: {
    cancel: function () {
      this.$router.push("/home/Wxzl");
    },
    //新增保存
    Save: function () {
      this.$axios({
        url: "/KeepQuality/addKeepQuality",
        method: "post",
        data: {
          endTime: this.formLabelAlign.endTime + "",
          equipmentId: this.formLabelAlign.equipmentId,
          equipmentNumber: this.formLabelAlign.equipmentNumber,
          startTime: this.formLabelAlign.startTime + "",
          testResults: this.formLabelAlign.testResults,
          testStatus: this.formLabelAlign.testStatus,
        },
      }).then(({ data }) => {
        if (data.code == 0) {
          this.$message.success("添加成功！");
          setTimeout(() => {
            this.$router.push("/home/Wxzl");
          }, 1000);
        } else {
          this.$message.error("添加失败！请重新添加！");
        }
      });
    },
    //渲染装备下拉框
    getData: function () {
      this.$axios({
        url: "/equipment/preselect",
        method: "get",
      }).then(({ data }) => {
        this.dropDown = data.equipmentNames;
      });
    },
  },
  mounted: function () {
    this.getData();
  },
};
</script>
<style lang="less" scoped>
.edit {
  padding: 40px;
}
.edit-box {
  display: flex;
  margin-bottom: 30px;
}
.form {
  height: auto;
  flex: 1;
  margin-right: 150px;
}
</style>